home *** CD-ROM | disk | FTP | other *** search
- Path: s02.pavilion.co.uk!usenet
- From: AJRobb@pavilion.co.uk (Andy J Robb)
- Newsgroups: comp.lang.c,comp.lang.c++,comp.os.ms-windows.programmer.misc,comp.os.msdos.programmer,comp.programming,comp.windows.ms.programmer
- Subject: Re: Date Arithmetic
- Date: Sun, 18 Feb 1996 17:58:04 GMT
- Organization: Pavilion Internet plc
- Message-ID: <4g7p9r$384@s02.pavilion.co.uk>
- References: <4g19kp$640@tracy.protocom.com> <3124A458.7BF8@f25mail.amd.com>
- NNTP-Posting-Host: poolb05.pavilion.co.uk
- X-Newsreader: Forte Free Agent 1.0.82
-
- Clark Archer <carcher@f25mail.amd.com> wrote:
-
- >Michael J. Karas wrote:
- >>
- >> I am working on an algorithm for a laser marking machine that writes
- >> expiration delays on to food product boxes. The algorithm needs to
- >> be able to add NNN days to todays date in the fastest manner possible
- >> without using any floating point arithmetic. I could use help from anyone
- >> that has C code for doing this. It would be nice if the solution took the
- >> leap year problem in to account including the special case of the year
- >> 2000. Thanks in advance to anyone who could share their knowledge on this
- >> subject.
- >> -----
- >> Michael Karas | EMail: mkaras@pclink.com
- >> Carousel Design Solutions | America OnLine: MJKaras
- >> 6021 Logan Avenue South | Voice: (612) 861-1284
- >> Minneapolis MN 55419 | Fax: (612) 861-1386
- >> -----
-
- >You could use the C runtime library function time() to get the current
- >time and then add NNN * SECS_PER_DAY to it and then convert back to a
- >struct tm like:
- >
- > #define SECS_PER_DAY 86400
-
- > time_t tmtNow;
- > struct tm tmThen;
-
- > tmtNow = time(NULL);
- > tmtNow += (nDaysToAdd * SECS_PER_DAY);
- > tmThen = *localtime(tmtNow);
-
- This requires an implementation where time_t is seconds.
- ISO/ANSI only requires an arithmetic type, e.g. using packed bitfields
- is legal - like MS-DOS. To be truly portable, you might want to go
- back to the Gaus algorithm (e.g. used in Linux kernel). If you want I
- can dig it out for you. This uses a handful of integer multiplies and
- divides and copes with all leap years.
-
- Regards,
- Andy Robb.
- -----BEGIN PGP PUBLIC KEY BLOCK-----
- Version: 2.6.2i
-
- mQCNAy/MpRwAAAEEAOt6uBYqT8yv9EmqNhK8m6v+bYi8QjnGW3Bo6iU1gsMj5pa6
- MHgq99c8deADbE3cbJ6uZS9v5pZE3WCf6HCQjlB5iULA5RZzMdAumd/WUzuL9UT3
- B44D9EqqFIL79FlYb56v4oKFqFp1/J2bIpYUwnUvabGzGjdLrpPl4P16x9sNAAUR
- tCNBbmR5IEogUm9iYiA8QUpSb2JiQHBhdmlsaW9uLmNvLnVrPrQhQW5keSBSb2Ji
- IDxBSlJvYmJAcGF2aWxpb24uY28udWs+
- =/wVD
- -----END PGP PUBLIC KEY BLOCK-----
-
-